<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="./js/ctx.js"></script>
</head>
<body>
<div id="cesiumContainer">
</div>
<script>
    var initCesium = new InitCesium();

    /**
     * This class is an example of a custom geocoder. It provides geocoding through the OpenStreetMap Nominatim service.
     * @alias OpenStreetMapNominatimGeocoder
     * @constructor
     */
    function OpenStreetMapNominatimGeocoder() {
    }

    /**
     * The function called to geocode using this geocoder service.
     *
     * @param {String} input The query to be sent to the geocoder service
     * @returns {Promise<GeocoderService~Result[]>}
     */
    OpenStreetMapNominatimGeocoder.prototype.geocode = function (input) {
        var endpoint = 'https://nominatim.openstreetmap.org/search';
        var resource = new Cesium.Resource({
            url: endpoint,
            queryParameters: {
                format: 'json',
                q: input
            }
        });

        return resource.fetchJson()
                .then(function (results) {
                    var bboxDegrees;
                    return results.map(function (resultObject) {
                        bboxDegrees = resultObject.boundingbox;
                        return {
                            displayName: resultObject.display_name,
                            destination: Cesium.Rectangle.fromDegrees(
                                    bboxDegrees[2],
                                    bboxDegrees[0],
                                    bboxDegrees[3],
                                    bboxDegrees[1]
                            )
                        };
                    });
                });
    };

    var viewer = initCesium.initViewer('cesiumContainer', {
        geocoder:new OpenStreetMapNominatimGeocoder()
    });



</script>
</body>
</html>